<!--内容开始-->
<form method="post" action="<?php echo Url::base(); ?>index.php/reg/reg" id="form1" name="form1">
<div class="password-con registered">
    <div class="psw">
        <p class="psw-p1">昵称</p>
        <input type="text" name="username"  value="<?php echo getParmByKey('username') ?>" id="username" placeholder="昵称" onblur="checkUser(this)" />

    </div>
    <div class="psw">
        <p class="psw-p1">输入密码</p>
        <input type="password" name="password"  value="<?php echo getParmByKey('password') ?>" id="password" placeholder="请输入密码" onblur="checkpassword()" />

    </div>
    <div class="psw">
        <p class="psw-p1">确认密码</p>
        <input type="password" id="confimpassword"  value="<?php echo getParmByKey('password') ?>" placeholder="请再次确认密码"  onblur="checkconfimpassword()" />
    </div>
    <div class="psw psw2">
        <p class="psw-p1" >手机号</p>
        <input type="text" placeholder="请输入手机"  value="<?php echo getParmByKey('phone') ?>" onblur="checkPhone()" name="phone" id="phone" />
        <button onclick="sendMsg()"  type="button" id="send">获取短信验证码</button>
    </div>
    <div class="psw psw3">
        <p class="psw-p1">手机验证码</p>
        <input type="text" name="code"  value="<?php echo getParmByKey('code') ?>" id="code" placeholder="请输入手机验证码" />
    </div>
    <div class="psw psw3">
        <p class="psw-p1">验证码</p>
        <input type="text" id="pageCode" name="pageCode" placeholder="请输入验证码" />
    </div>
    <div class="yanzhentu">
        <div class="yz-tu f-l">
            <img id="codeimg" src="<?php echo Url::base(); ?>index.php/reg/getCode?rand=<?php echo rand(100000,10000000);?>" />
        </div>
        <p class="f-l">看不清？<a href="javascript:change()">换张图</a></p>
        <div style="clear:both;"></div>
    </div>
    <div class="agreement">
        <input id="hobby" type="checkbox" name="hobby"></input>
        <p>我有阅读并同意<span >《宅客微购网站服务协议》</span> <div id="spanshow"></div></p>
    </div>
    <button onclick="check()" type="button" class="psw-btn">立即注册</button>
    <p class="sign-in">已有账号？请<a href="" >登录</a></p>
</div>
</form>
<script>
    var url = '<?php echo Url::base(); ?>';
function change(){
    $('#codeimg').attr('src',url+'index.php/reg/getCode?rand='+Math.random())
}
<?php if(isset($msg)){ echo 'alert("'.$msg.'");';} ?>
    var count = 60;
var timename = null;
    var control = true;
    function sendMsg(){
        if(control){
            control=false;

        if($("#phone").val()==""||!/^(17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test($("#phone").val()))
        {
            control=true;
            alert('请输入正确手机号');
            return;
        }

        $.ajax({

            type: 'get',

            url:  url+'index.php/reg/sendRegPhone',

            data: {phone:$("#phone").val()} ,

            success: function(data){
                if(data.msg ){
                    timename=setInterval(function() {
                        if(count == 0){
                            count = 60;
                            control= true;
                            $("#send").html("获取短信验证码")

                            clearInterval(timename)
                            return;
                        }
                        $("#send").html(count+"后重新发送")

                        count --;
                    },1000);
                }else{
                    control=true;
                    alert(data.data)
                }
            },

            dataType: 'json'

        });
        }
    }
    function checkPhone(){
        $("#phonespan").remove()
        if($("#phone").val()==""||!/^(17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test($("#phone").val()))
        {


            $("#phone").after(' <span id="phonespan" class="cuo">手机号不正确</span>')
        }else{
            $("#phone").after(' <span id="phonespan" class="dui"></span>')
        }
    }
    var issbmit = true;
    function checkpassword(){
        $("#passspan").remove()
        var msg = "";
        var password = $("#password").val()
        if(password ==""){
            return false;
        }
        var reg=/^(([a-z]+[0-9]+)|([0-9]+[a-z]+))[a-z0-9]*$/i;

        if(password.length <6||!reg.test(password)){
            msg='密码由6-16的字母、数字、符号组成'
        }
        console.log(msg)

        if(msg == ""){

            $("#password").after(' <span id="passspan" class="dui"></span>')
            return true
        }else{
            $("#password").after(' <span id="passspan" class="cuo">'+msg+'</span>')
            return false;
        }


    }
    function checkconfimpassword(){

        $("#confimpasswordspan").remove()
        var msg = "";
        var password = $("#confimpassword").val()
        if(password  ==""){
            return false;
        }
        if(password !=$("#password").val()){
            msg= "密码不一致"
        }
        if(msg == ""){

            $("#confimpassword").after(' <span id="confimpasswordspan" class="dui"></span>')
            return true
        }else{
            $("#confimpassword").after(' <span id="confimpasswordspan" class="cuo">'+msg+'</span>')
            return false;
        }


    }
    function checkUser(obj){
        $("#usernamespan").remove()
        if($(obj).val() == ""){
            return false;
        }
        console.log($(obj).val())
        $.ajax({

            type: 'get',

            url:  url+'index.php/reg/checkUserName',

            data: {username:$(obj).val()} ,

            success: function(data){
                console.log(data)
                var msg = "";
                if(data.code==-1){
                    msg = "检查用户名失败请刷新再试"
                }

                if(data.code==1){
                    msg = "用户名已经存在"
                }
//                alert(msg)
                $("#usernamespan").remove()
                if(msg == ""){
                    $(obj).after(' <span id="usernamespan" class="dui"></span>')
                }else{
                    $(obj).after(' <span id="usernamespan" class="cuo">'+msg+'</span>')
                }
            },

            dataType: 'json'

        });
    }
    function check(){


        var flag = true;
        $("#usernamespan").remove()
        if($("#username").val() == ""){
            flag = false;

            $("#username").after(' <span id="usernamespan" class="cuo">用户名不能为空</span>')
        }else{

            $("#username").after(' <span id="usernamespan" class="dui"></span>')
        }
        var password = $("#password").val()
        var reg=/^(([a-z]+[0-9]+)|([0-9]+[a-z]+))[a-z0-9]*$/i;
        $("#passspan").remove()
        if(password ==""){
            flag = false;

            $("#password").after(' <span id="passspan" class="cuo">密码不能为空</span>')
        }else if(!reg.test(password)){
            flag = false;

            $("#password").after(' <span id="passspan" class="cuo">密码由6-16的字母、数字、符号组成</span>')
        }else{
            $("#password").after(' <span id="passspan" class="dui"></span>')
        }


        $("#confimpasswordspan").remove()
        var cpassword = $("#confimpassword").val()
        if(cpassword  ==""){
            flag = false;

            $("#confimpassword").after(' <span id="confimpasswordspan" class="cuo">密码不能为空</span>')
        }else{
            $("#confimpassword").after(' <span id="confimpasswordspan" class="dui"></span>')
            $("#confimpasswordspan").remove()
            if(cpassword  !=password){
                flag = false;

                $("#confimpassword").after(' <span id="confimpasswordspan" class="cuo">密码不一致</span>')
            }else{
                $("#confimpassword").after(' <span id="confimpasswordspan" class="dui"></span>')
            }
        }

        $("#phonespan").remove()
        var phone =$("#phone").val();
        if($("#phone").val()==""||!/^(17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test($("#phone").val()))
        {
            flag = false;

            $("#phone").after(' <span id="phonespan" class="cuo">手机号不正确</span>')
        }else{
            $("#phone").after(' <span id="phonespan" class="dui"></span>')
        }
        $("#codespan").remove()
        if($("#code").val()=="")
        {
            flag = false;

            $("#code").after(' <span id="codespan" class="cuo">手机验证码不正确</span>')
        }else
            $("#code").after(' <span id="codespan" class="dui"></span>')


        $("#pagecodespan").remove()
        if($("#pageCode").val()=="")
        {
            flag = false;

            $("#pageCode").after(' <span id="pagecodespan" class="cuo">验证码不一致</span>')
        }else{
            $("#pageCode").after(' <span id="pagecodespan" class="dui">验证码不一致</span>')
        }
//alert(document.getElementById('hobby').checked)
        if(!document.getElementById('hobby').checked){
            $("#spanshow1").remove()
            flag = false;
//            $("#spanshow").after(' <span id="spanshow1" class="cuo"></span>')
            alert("请勾选协议")
        }

        if(flag){
          document.form1.submit();
        }
    }
</script>